package jesss.commands;

import com.amazonaws.services.s3.AmazonS3;
import jesss.options.JesssOptions;

/**
 * User: Lee
 * Date: 8/18/13
 * Time: 12:54 AM
 */
public class JesssCommandFactoryImpl implements JesssCommandFactory{

    private static JesssCommandFactory _instance = null;

    private JesssCommandFactoryImpl(){
    }

    public static synchronized JesssCommandFactory getInstance() {
        if (_instance == null) {
            _instance = new JesssCommandFactoryImpl();
        }
        return _instance;
    }

    @Override
    public JesssCommand createCommand(AmazonS3 amazonS3, String commandName, boolean shouldDisplayVerbose, String[] args) throws Exception {
        JesssCommand jesssCommand = null;
        JesssOptions jesssOptions = new JesssOptions.Builder(commandName).amazonS3(amazonS3).shouldDisplayVerbose(shouldDisplayVerbose).args(args).build();

        try {
            switch (CommandType.fromShortName(commandName)) {
                case ListBuckets: {
                    jesssCommand = new ListBucketsCommand(jesssOptions);
                    break;
                }
                case ListObjects: {
                    jesssCommand = new ListObjectsCommand(jesssOptions);
                    break;
                }
                case CreateBucket: {
                    jesssCommand = new CreateBucketCommand(jesssOptions);
                    break;
                }
                case DeleteBucket: {
                    jesssCommand = new DeleteBucketCommand(jesssOptions);
                    break;
                }
                case PutObject: {
                    jesssCommand = new PutObjectCommand(jesssOptions);
                    break;
                }
                case GetObject: {
                    jesssCommand = new GetObjectCommand(jesssOptions);
                    break;
                }
                case DeleteObject: {
                    jesssCommand = new DeleteObjectCommand(jesssOptions);
                    break;
                }
                case CopyObject: {
                    jesssCommand = new CopyObjectCommand(jesssOptions);
                    break;
                }
                case DownloadDirectory: {
                    jesssCommand = new DownloadDirectoryCommand(jesssOptions);
                    break;
                }
                case MoveObject: {
                    jesssCommand = new MoveObjectCommand(jesssOptions);
                    break;
                }
                case UploadDirectory: {
                    jesssCommand = new UploadDirectoryCommand(jesssOptions);
                    break;
                }
                case SearchObject: {
                    jesssCommand = new SearchForStringInObjectCommand(jesssOptions);
                    break;
                }
                case SearchObjects: {
                    jesssCommand = new SearchForStringInObjectsCommand(jesssOptions);
                    break;
                }
                default:
            }

        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return jesssCommand;
    }
}
